package com.woniuxy.carrental.service.impl;

import com.woniuxy.carrental.entity.Credit;
import com.woniuxy.carrental.mapper.CreditMapper;
import com.woniuxy.carrental.service.CreditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 信用表，贷款申请方法实现类
 */
@Service
public class CreditServiceImpl implements CreditService {

   @Autowired
    CreditMapper creditMapper;

   //客户申请贷款，附带状态码
    @Override
    public void addCredit(Credit credit) {


        try {
            creditMapper.addCredit(credit);
        } catch (Exception e) {
           throw  new RuntimeException("该账户不存在，添加错误");
        }

    }

    //查询客户提交贷款状态的所有信息
    @Override
    public List<Credit> selectAllCredit(boolean apply) {
        List<Credit> credits = creditMapper.selectAllCredit(apply);
        return credits;
    }

    //贷款申请审核通过
    @Override
    public void updateCreditByTrue(Integer cid) {

        creditMapper.updateCreditByTrue(cid);
    }

    //判定审核不通过
    @Override
    public void updateAuditByFalser(Integer cid) {

        creditMapper.updateAuditByFalser(cid);
    }

    //做个分页
    @Override
    public List<Credit> selectPage(int pageIndex, int pageSize, Credit credit) {
        List<Credit> credits = creditMapper.selectPage(pageIndex, pageSize, credit);

        return credits;
    }

    //查询总条数
    @Override
    public int selectCreditCount() {
        int i=creditMapper.selectCreditCount();
        return i;
    }

    //根据贷款申请，获取客户的信息


    @Override
    public Credit selectCredieByCid(Integer cid) {

        Credit credit = creditMapper.selectCredieByCid(cid);
        return credit;
    }
}
